<template>
  <div>
    <nav-bar class="nav-bar">
      <template v-slot:nav-left>
        <img src="@/assets/img/common/back.svg" class="back" @click="backClick">
      </template>
      <template v-slot:nav-center>
        <div class="nav-center">
          <div 
          v-for="(item,index) in title" 
          :key="item.index" 
          class="navbar-title-item" 
          @click="titleClick(index)" 
          :class="{active:currentIndex===index}">
          {{item}}
        </div>
        </div>
      </template>
    </nav-bar>
  </div>
    
</template>

<script>
import NavBar from "@/components/common/navbar/NavBar";
export default {
  components: {
    NavBar
  },
  data() {
    return {
      title: ["商品", "参数", "评论", "推荐"],
      currentIndex: 0
    };
  },
  methods: {
    backClick() {
      this.$router.go(-1);
    },
    titleClick(index) {
      this.currentIndex = index;
      this.$emit('titleClick',index)
    }
  }
};
</script>

<style scoped>
.nav-bar {
  text-align: center;
  font-size: 15px;
  line-height: 44px;
  font-weight: 600;
}

.nav-center {
  display: flex;
}

.back {
  margin-top: 10px;
}

.navbar-title-item {
  flex: 1;
}

.active {
  color: deeppink;
}
</style>